Fix activating features in dependencies transitively
authorAlex Crichton <alex@alexcrichton.com>
Mon, 3 Aug 2015 22:10:31 +0000 (15:10 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 3 Aug 2015 22:10:31 +0000 (15:10 -0700)
When activating the feature `foo/bar` you're actually activating both the
feature `foo` and the `bar` feature of the relevant package. Cargo previously
forgot to activate the `foo` feature, and this commit fixes that up.

Closes #1871

src/cargo/core/resolver/mod.rs
tests/test_cargo_features.rs

index 0fe74b8d8f9e08913d7272fa90ba44fc278b471d..223966a9dd9c5d9f2dac00c7c28ab29ed762d6ab 100644 (file)
@@ -556,6 +556,7 @@ fn build_features(s: &Summary, method: Method)
         match parts.next() {
             Some(feat) => {
                 let package = feat_or_package;
+                used.insert(package.to_string());
                 deps.entry(package.to_string())
                     .or_insert(Vec::new())
                     .push(feat.to_string());
index 33a058f0e32268b288022af8868efd7c117ae452..11211087b0bd0d050f8dbce9e400deedcfc21ef5 100644 (file)
@@ -769,3 +769,41 @@ test!(optional_and_dev_dep {
 {compiling} test v0.1.0 ([..])
 ", compiling = COMPILING)));
 });
+
+test!(activating_feature_activates_dep {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name    = "test"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            foo = { path = "foo", optional = true }
+
+            [features]
+            a = ["foo/a"]
+        "#)
+        .file("src/lib.rs", "
+            extern crate foo;
+            pub fn bar() {
+                foo::bar();
+            }
+        ")
+        .file("foo/Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+
+            [features]
+            a = []
+        "#)
+        .file("foo/src/lib.rs", r#"
+            #[cfg(feature = "a")]
+            pub fn bar() {}
+        "#);
+
+    assert_that(p.cargo_process("build").arg("--features").arg("a").arg("-v"),
+                execs().with_status(0));
+});